// Time.cpp

#include "Time.hpp"

Time::Time(int start, int end)
{
  // Initialize the various times.
  t0 = start;
  tf = end;
  t = start;
}

bool Time::step(std::list<Organism>& orgs)
{
  int dorg;
  std::list<Organism>::iterator iter, iter2;  

  // Loop over all of the organisms:
  for(iter = orgs.begin(); iter != orgs.end();) {
    dorg = iter->advance();

    if(dorg == 1) orgs.push_front(*iter);
		 
    iter2 = iter;
    iter++;
    if(dorg == -1) orgs.erase(iter2);
  }
  
  t++;
  return t < tf;
}
